package com.v.air.app.ui;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;

import com.v.air.app.AppManager;
import com.v.air.app.BaseActivity;
import com.v.air.app.R;
import com.v.air.app.adapter.SettingAdapter;
import com.v.air.app.bean.CityBean;
import com.v.air.app.tools.PreferencesTool;
import com.v.air.app.tools.StringUtils;

public class SettingActivity extends BaseActivity {
	private ListView listView;
	private SettingAdapter adapter;
	private TextView titleTextView;

	public static void startActivity(Context context) {
		context.startActivity(new Intent(context, SettingActivity.class));
	}

	@Override
	public int bindLayout() {
		// TODO Auto-generated method stub
		return R.layout.listview;
	}

	@Override
	public void initView(View view) {
		titleTextView = (TextView) view.findViewById(R.id.title);
		listView = (ListView) view.findViewById(R.id.listview);
		adapter = new SettingAdapter(this);
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View view, int arg2,
					long arg3) {
				TextView textView = (TextView) view.findViewById(R.id.name);
				CityBean cityBean = (CityBean) textView.getTag();
				if (cityBean != null) {
					myApplication.setCityBean(cityBean);
					AppManager.getAppManager().finishActivity();
				}

			}
		});
		String title = PreferencesTool.getString(getContext(), "APP_TITLE");
		if (StringUtils.isEmpty(title)) {
			titleTextView.setText(R.string.app_title);
		} else {
			titleTextView.setText(title);
		}
	}

	@Override
	public void initData(Context mContext) {
		adapter.setData(CityBean.getCityList());
		adapter.notifyDataSetChanged();
	}

	@Override
	public void initListener() {
		// TODO Auto-generated method stub

	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub

	}

	@Override
	public void destroy() {
		// TODO Auto-generated method stub

	}

}
